<?php

/* @var $this yii\web\View */
/* @var $form yii\bootstrap\ActiveForm */
/* @var $model common\models\ContactForm */

use yii\helpers\Url;
use common\helpers\Render;
use common\models\User;
use common\models\UserLogin;

$this->addCrumbs('用户列表', 'user/user-list');
$this->title = '账户详情';
?>
<div class="box-content gap">
    <div class="flyer-form pane">
        <div class="form-item">
            <div class="item-inline">
                <div class="input-title">用户名</div>
                <div class="input-inline input-mid"><?= Render::value($user, 'username', '--') ?></div>
            </div>
            <div class="item-inline">
                <div class="input-title">所属角色</div>
                <div class="input-inline input-mid"><?= Render::show(User::$roleSelector, $user->role) ?></div>
            </div>
        </div>
        <div class="form-item">
            <div class="item-inline">
                <div class="input-title">手机号</div>
                <div class="input-inline input-mid"><?= Render::value($user, 'mobile', '--') ?></div>
            </div>
            <div class="item-inline">
                <div class="input-title">邮箱</div>
                <div class="input-inline input-mid"><?= Render::value($user, 'email', '--') ?></div>
            </div>
        </div>
        <div class="form-item">
            <div class="item-inline">
                <div class="input-title">支付宝</div>
                <div class="input-inline input-mid"><?= Render::value($user, 'alipay', '--') ?></div>
            </div>
            <div class="item-inline">
                <div class="input-title">微信</div>
                <div class="input-inline input-mid"><?= Render::value($user, 'wechat', '--') ?></div>
            </div>
        </div>
    </div>
    <div class="data-title mb-10px"><i class="icon-credit-card"></i> 账户信息</div>
    <div class="flyer-form pane">
        <div class="form-item">
            <div class="item-inline">
                <div class="input-title">可用余额</div>
                <div class="input-inline input-mid"><span class="flyer-status green thin"><?= Render::amount($user->account->usable) ?></span></div>
            </div>
            <div class="item-inline">
                <div class="input-title">冻结金额</div>
                <div class="input-inline input-mid"><span class="flyer-status red thin"><?= Render::amount($user->account->frozen) ?></span></div>
            </div>
        </div>
        <div class="form-item">
            <div class="item-inline">
                <div class="input-title">总充值金额</div>
                <div class="input-inline input-mid"><?= Render::amount($user->account->recharge) ?></div>
            </div>
            <div class="item-inline">
                <div class="input-title">总提现金额</div>
                <div class="input-inline input-mid"><?= Render::amount($user->account->withdraw) ?></div>
            </div>
        </div>
        <?php if($user->designer()) {
            ?>
        <div class="form-item">
            <div class="item-inline">
                <div class="input-title">累计赚取</div>
                <div class="input-inline input-mid"><?= Render::amount($user->account->earn) ?></div>
            </div>
        </div>
        <?php } ?>
    </div>
    <div class="data-title mt-20px mb-10px"><i class="icon-star"></i> 优惠劵</div>
    <div class=" flyer-table">
        <table id="info-table" cellspacing="0" cellpadding="0">
            <thead>
            <tr>
                <th class="first"><i class="icon-flag"></i> 名称</th>
                <th><i class="icon-time"></i> 开始时间</th>
                <th><i class="icon-time"></i> 结束时间</th>
                <th><i class="icon-bell-alt"></i> 状态</th>
            </tr>
            </thead>
            <tbody>
            <?php
                if($user->coupons) {
                    foreach($user->coupons as $coupon) { ?>
                        <tr>
                            <td class="first"><?= $coupon['name'] ?></td>
                            <td><?= date('Y-m-d H:i:s', $coupon->begin_at) ?></td>
                            <td><?= date('Y-m-d H:i:s', $coupon->finish_at) ?></td>
                            <td><?= Render::show(UserSkill::$statusSelector, $coupon['status']) ?></td>
                        </tr>
                    <?php }
                }
                else { ?>
                    <tr><td colspan="4"><i class="icon-ban-circle"></i> 暂未获得任何优惠劵！</td></tr>
                <?php }
                    ?>
            </tbody>
        </table>
    </div>
    <div class="data-title mt-20px mb-10px"><i class="icon-map-marker"></i> 登录历史</div>
    <div class=" flyer-table">
        <table id="info-table" cellspacing="0" cellpadding="0">
            <thead>
            <tr>
                <th class="first"><i class="icon-list-ol"></i> 登陆时间</th>
                <th><i class="icon-map-marker"></i> 登陆地址</th>
                <th><i class="icon-location-arrow"></i> IP</th>
                <th><i class="icon-desktop"></i> 客户端</th>
                <th><i class="icon-upload-alt"></i> 登陆方式</th>
            </tr>
            </thead>
            <tbody>
            <?php
                if($user->logins) {
                    foreach($user->logins as $login) { ?>
                        <tr>
                            <td class="first"><?= date('Y-m-d H:i', $login['created_at']) ?></td>
                            <td><?= $login['address'] ?></td>
                            <td><?= $login['ip'] ?></td>
                            <td><?= UserLogin::$clientSelector[$login['client']] ?></td>
                            <td><?= UserLogin::$loginTypeSelector[$login['login_type']] ?></td>
                        </tr>
                    <?php }
                }
                else { ?>
                    <tr><td colspan="5"><i class="icon-ban-circle"></i> 暂无任何登陆信息！</td></tr>
                <?php }?>
            </tbody>
        </table>
    </div>
</div>